package com.firstclass.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.firstclass.dao.TakestudentDao;
import com.firstclass.entity.TakestudentEntity;
import com.firstclass.entity.vo.CollegeVo;
import com.firstclass.service.TakestudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("takestudentService")
public class TakestudentServiceImpl extends ServiceImpl<TakestudentDao, TakestudentEntity> implements TakestudentService {

    @Autowired
    private TakestudentDao takestudentDao;

    @Override
    public List<TakestudentEntity> queryByCondition(String name, String num, String college, String profess) {
        final QueryWrapper<TakestudentEntity> wrapper = new QueryWrapper<>();
        if (StrUtil.isNotBlank(name)) {
            wrapper.like("name", name);
        }
        if (StrUtil.isNotBlank(num)) {
            wrapper.like("num", num);
        }
        if (StrUtil.isNotBlank(college)) {
            wrapper.like("college", college);
        }
        if (StrUtil.isNotBlank(profess)) {
            wrapper.like("profess", profess);
        }
        return this.list(wrapper);
    }

    @Override
    public boolean save(TakestudentEntity takestudentEntity) {
        if (takestudentEntity.getId() == null) {
            takestudentDao.insert(takestudentEntity);
        } else {
            takestudentDao.updateById(takestudentEntity);
        }
        return true;
    }

    @Override
    public List<CollegeVo> collegeNums() {
        return takestudentDao.collegeNums();
    }

}
